package com.tongtong.stsuserapi.controller;

import com.tongtong.stscommon.message.STSMessage;
import com.tongtong.stsuserapi.pojo.User;
import com.tongtong.stsuserapi.service.base.ManagerService;
import com.tongtong.stsuserapi.service.base.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * 管理员控制器
 */
@Api(tags="管理员接口")
@RestController
@RequestMapping("/sts/manager")
public class ManagerController {

	@Autowired
	UserService userService;

	@Autowired
	ManagerService managerService;

	@ApiOperation("添加用户")
	@PostMapping("/add")
	STSMessage addUser(@RequestPart("user") User user, @RequestPart("file") MultipartFile file) throws Exception {
		return managerService.addUser(user,file);
	}

	@ApiOperation("批量删除用户")
	@DeleteMapping("/delete")
	@ApiImplicitParam(name = "userIds",value = "用户id列表")
	public STSMessage deleteUserById(@RequestBody List<Long> userIds) {
		return managerService.DeleteUsersByList(userIds);
	}

	@ApiOperation("搜索用户")
	@PostMapping("/search")
	STSMessage searchByPage(@RequestBody User user, Integer page, Integer pageSize) {
		return userService.dynamicSearchByPage(user,page,pageSize);
	}

	@ApiOperation("修改用户")
	@PatchMapping("/alter")
	STSMessage alterUser(@RequestBody User user) {
		return managerService.alterUser(user);
	}

	@ApiOperation("获取待审核列表")
	@ApiImplicitParam(name = "codeState",value = "审核状态(0待审核,1通过,2拒绝)")
	@GetMapping("/code")
	STSMessage getCodesToBeAudited(Integer codeState, Integer page, Integer pageSize) {
		return managerService.getCodesToBeAudited(codeState, page, pageSize);
	}

	@ApiOperation("审核收款码")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "result",value = "审核结果(1为通过,2为拒绝)"),
			@ApiImplicitParam(name = "reason",value = "拒绝原因(若审核通过传入null即可)")
	})
	@PatchMapping("/code")
	STSMessage codeAudit(Long codeId, Integer result,String reason) {
		return managerService.codeAudit(codeId,result,reason);
	}

}
